#include "mainwindow.h"
#include <QApplication>

#include <functional>
#include <iostream>

//============================================================
//c++11 策略模式
class IntSubstract
{
public:
    int operator()(int a, int b)
    {
        return a-b;
    }
};

class IntAdd
{
public:
    int operator()(int a, int b)
    {
        return a+b;
    }
};

class IntOperator
{
public:
    typedef std::function<int(int, int)> fFun;
    IntOperator(fFun f, int a, int b) : _fun(f), _left(a), _right(b), _ret(0)
    {

    }

    int GetResult()
    {
        return _fun(_left, _right);
    }

private:
    fFun _fun;
    int _left;
    int _right;
    int _ret;
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    IntAdd myAdd;
    IntSubstract mySub;

    IntOperator addOP(myAdd, 1, 2);
    IntOperator subOP(mySub, 4, 5);

    std::cout << "add is: " << addOP.GetResult() << std::endl;
    std::cout << "sub is: " << subOP.GetResult() << std::endl;

    //w.setWindowTitle(QStringLiteral("安可信电信NBIoT转换工具"));
    w.setWindowTitle(u8"安可信电信NBIoT转换工具");
    w.show();

    return a.exec();
}
